package com.bobo.web.provider.controller.nio_redis_zookeeper.bio;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class Socket_01Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8080);
        System.out.println("wait client。。。。。");
        Socket socket = serverSocket.accept();
        System.out.println("success。。。。");
        DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
        DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
        Scanner scanner = new Scanner(System.in);
        System.out.println("wait client message");
        String clientMsg = dataInputStream.readUTF();
        while (!clientMsg.equals("over")){
            System.out.println("客户端："+clientMsg);
            System.out.println("wait server in：");
            String serverMsg = scanner.nextLine();
            dataOutputStream.writeUTF(serverMsg);
            dataOutputStream.flush();
            System.out.println("服务器："+serverMsg);
            System.out.println("wait client message");
            clientMsg = dataInputStream.readUTF();
        }
        dataInputStream.close();
        socket.close();

    }
}
